﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using TYAJZWeb.Data;
using TYAJZWeb.Models;

namespace TYAJZWeb.Controllers
{
    public class BaseController : Controller
    {
        protected TYAJZDataContext Context = null;
        protected readonly int PAGESIZE = 20;

        protected BaseController()
        {
            Context = new TYAJZDataContext();

            UserTypes type = UserTypes.Anonymous;

            if (System.Web.HttpContext.Current.Items["UserType"] != null)
                Enum.TryParse<UserTypes>(System.Web.HttpContext.Current.Items["UserType"].ToString(), out type);

            ViewBag.UserType = type;

        }

        protected int CurrentUserId
        {
            get
            {
                if (System.Web.HttpContext.Current.Items["UserId"] == null)
                {
                    return 0;
                }
                else
                {
                    return Convert.ToInt32(System.Web.HttpContext.Current.Items["UserId"]);
                }
            }
        }

        protected UserTypes CurrentUserType
        {
            get
            {
                return (UserTypes)ViewBag.UserType;
            }
        }

        protected void AddSuccessMsg(string message)
        {
            TempData.Add("Success", message);
        }

        protected void AddErrorMsg(string message)
        {
            TempData.Add("Error", message);
        }
    }
}
